﻿using System;
using System.Linq.Expressions;

namespace Preactor.ObjectModel.Entities
{
    public static class PreactorRecordExtensions
    {
        internal static TKey GetValue<T, TKey>(this T record, Expression<Func<T, TKey>> keySelector) where T : PreactorRecord where TKey : class
        {
            string propertyName = ((MemberExpression)keySelector.Body).Member.Name;
            return record.GetValue(propertyName) as TKey;
        }

        internal static void SetValue<T, TKey>(this T record, Expression<Func<T, TKey>> keySelector, TKey value) where T : PreactorRecord
        {
            string propertyName = ((MemberExpression)keySelector.Body).Member.Name;
            record.SetValue(propertyName, value);
        }
    }
}
